﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using HaiFengShop.Utils;
using HaiFengShop.Filter;
using HaiFengShop.Service;
using System.IO;
using System.DrawingCore.Imaging;
using HaiFengShop.Entity;
using Newtonsoft.Json.Linq;

namespace HaiFengShop.Controllers
{
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class AddressController : ControllerBase
    {
        private readonly AddressService addressService;
        public AddressController(AddressService addressService)
        {
            this.addressService = addressService;
        }

        /// <summary>
        /// 获取个人收货地址
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetAddresses()
        {
            return Ok(addressService.GetAddresses());
        }
      
        /// <summary>
        /// 获取个人详细地址信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult AddressDetail(int id)
        {
            return Ok(addressService.AddressDetail(id));
        }

        /// <summary>
        /// 获取个人详细地址信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult SaveAddress([FromBody]DTOAddress addr)
        {
            return Ok(addressService.SaveAddress(addr));
        }


        /// <summary>
        /// 删除个人收货地址
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult DeleteAddress([FromBody]dynamic postData)
        {
            int id = postData.id;
            return Ok(addressService.DeleteAddressById(id));
        }

    }
}
